{include file="public/header"}
<title>添加</title>
<meta name="keywords" content="">
<meta name="description" content="">
<link href="/static/admin/lib/webuploader/0.1.5/webuploader.css" rel="stylesheet" type="text/css" />
<body>
<article class="page-container">
    <form action="" method="post" class="form form-horizontal" id="form-admin-add">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>父级选择：</label>
            <div class="formControls col-xs-8 col-sm-9"> <span class="select-box">
				<select name="pid" class="select">

                    <option value="">————请选择————</option>
                    <option value="0">|——无父级</option>
                    {volist name="all_data" id="vo"}
                        <option value="{$vo.pid}" {if $vo.id eq $data.id}selected{else/}{/if}>{:str_repeat('|——',$vo.level)}{$vo.title}</option>
                    {/volist}

				</select>
				</span>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>名称：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" autocomplete="off" value="{$data.name}" placeholder="" id="name" name="name">
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>来源：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" autocomplete="off" value="{$data.source}"  placeholder="" id="source" name="source">
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">图片：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <div class="uploader-thum-container">
                    <div id="fileList" class="uploader-list"><img id="imageview" style="width:50px;height:50px;" src='{$data.image}'></div>
                    <div > <input type="file" name="image" id="fileupload" ></div>
                </div>
            </div>
        </div>
        <input type="hidden" name="id" value="{$data.id}">
        <input type="hidden" name="old_image" value="{$data.image}">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>标题：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" autocomplete="off" value="{$data.title}" placeholder="" id="title" name="title">
            </div>
        </div>
        <input type="hidden" name="id" value="{$data.id}">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>描述：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <textarea cols="" rows="" name="descr" class="textarea" placeholder="说点什么...">{$data.descr}</textarea>
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>内容：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <script id="editor" type="text/plain" name="content" style="width:100%;height:400px;">{$data.content|raw}</script>
                </div>
                </div>

                <div>
                <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                    <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
                    </div>
                    </div>
                    </form>
                    </article>
                {include file="public/footer"}
                <!--请在下方写此页面业务相关的脚本-->
                <script type="text/javascript" src="/static/admin/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
                <script type="text/javascript" src="/static/admin/lib/jquery.validation/1.14.0/validate-methods.js"></script>
                <script type="text/javascript" src="/static/admin/lib/jquery.validation/1.14.0/messages_zh.js"></script>
                <script type="text/javascript" src="/static/admin/lib/My97DatePicker/4.8/WdatePicker.js"></script>
                <script type="text/javascript" src="/static/admin/lib/webuploader/0.1.5/webuploader.min.js"></script>
                <script type="text/javascript" src="/static/admin/lib/ueditor/1.4.3/ueditor.config.js"></script>
                <script type="text/javascript" src="/static/admin/lib/ueditor/1.4.3/ueditor.all.min.js"> </script>
                <script type="text/javascript" src="/static/admin/lib/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script>
                <script type="text/javascript">
                    $(function(){
                        $('.skin-minimal input').iCheck({
                            checkboxClass: 'icheckbox-blue',
                            radioClass: 'iradio-blue',
                            increaseArea: '20%'
                        });

                        $("#form-admin-add").validate({
                            onkeyup:false,
                            focusCleanup:true,
                            success:"valid",
                            submitHandler:function(form){
                                $(form).ajaxSubmit({
                                    type: 'post',
                                    url: "{:url('edit')}" ,
                                    success: function(data){
                                        console.log(data);
                                        layer.msg('添加成功!',{icon:1,time:1000});
                                        if(data == 200){
                                            layer.msg("添加成功",{icon:1,time:1500},function(){
                                                parent.window.location.href="{:url('index')}";
                                                var index=parent.layer.getFrameIndex(window.name);
                                                parent.layer.close(index);
                                            });
                                        }else{
                                            layer.msg("失败",{icon:1,time:1500});
                                        }
                                    },
                                    error: function(XmlHttpRequest, textStatus, errorThrown){
                                        layer.msg('error!',{icon:1,time:1000});
                                    }
                                });
                                // var index = parent.layer.getFrameIndex(window.name);
                                // parent.$('.btn-refresh').click();
                                // parent.layer.close(index);
                            }
                        });
                        $(function(){
                            var ue = UE.getEditor('editor');
                        });
                    });
                </script>
                <script>
                    $(function() {
                        /*原理是把本地图片路径："D(盘符):/image/..."转为"http://..."格式路径来进行显示图片*/
                        $("#fileupload").change(function() {
                            var $file = $(this);
                            var objUrl = $file[0].files[0];
                            //获得一个http格式的url路径:mozilla(firefox)||webkit or chrome
                            var windowURL = window.URL || window.webkitURL;
                            //createObjectURL创建一个指向该参数对象(图片)的URL
                            var dataURL;
                            dataURL = windowURL.createObjectURL(objUrl);
                            $("#imageview").attr("src",dataURL);
                            // $("#imageview").attr();
                        });
                    });
                </script>
                <!--/请在上方写此页面业务相关的脚本-->
</body>
</html>